import fs from "fs";
import { dirname, resolve } from "path";
import { fileURLToPath } from "url";

const filename = fileURLToPath(import.meta.url);
const __dirname = dirname(filename);
// console.log(__dirname);
function generateCount(count, fn) {
  let result = {};
  return function (...args) {
    result[args[0]] = args[1];
    if (--count == 0) {
      fn(result);
    }
  };
}

const cb = generateCount(2, function (val) {
  console.log("done", val);
});
fs.readFile(resolve(__dirname, "a.txt"), "utf8", (err, data) => {
  cb("a.txt", data);
});

fs.readFile(resolve(__dirname, "b.txt"), "utf8", (err, data) => {
  cb("b.txt", data);
});

// TODOS: babel编译如何可以插入高阶函数的应用，不改变业务代码的同时应用高阶函数
